const Base = require('../base.js');
const puppeteer = require('puppeteer')
const common = require('../../common/index')
/*截屏*/
module.exports = class extends Base {
    async indexAction() {
        const cn = new common()
        const browser = await puppeteer.launch()
        const page = await browser.newPage()
        await page.emulate(puppeteer.devices['iPhone 6']);
        await page.goto('https://duxinggj-1251133427.cos.ap-guangzhou.myqcloud.com/haibao/moban.html?' + cn.jsonToString(this.get()))

        //截取某个元素的图片
        let waikwer = await page.$('#waikwer');
        let file_name = cn.randomString(14) + new Date().getTime() + '.jpg'
        let wjm = 'www/static/upimg/' + file_name
        const jpge = await waikwer.screenshot({
            path: wjm, //图片保存路径
            type: 'jpeg'
        });
        this.ctx.type = "jpeg" //设置返回类型
		this.body = jpge
        
    }
};
